package com.dxg.msns.music.mapper;

import com.dxg.msns.music.api.MusicFavor;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;


import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface MusicFavorMapper extends Mapper<MusicFavor> {


    @Select("SELECT music_id FROM music_favor WHERE collector_id = #{uid} AND favor_status = 1")
    List<String> queryByUid(String uid);

    @Select("SELECT favor_status FROM music_favor WHERE collector_id = #{uid} = #{uid} ")
    List<String> queryFavorStatusByUid(String uid);

    @Update("UPDATE music_favor SET favor_status = #{favorStatus} WHERE collector_id = #{collectorId} AND music_id = #{musicId}")
    int updateStatusByCollectorIdAndMusicId(String collectorId, String musicId, Integer favorStatus);


    // 根据 collectorId 和 musicId 查找收藏记录
    @Select("SELECT * FROM music_favor WHERE collector_id = #{collectorId} AND music_id = #{musicId}")
    MusicFavor selectByCollectorIdAndMusicId(String collectorId, String musicId);


    // 根据 collectorId 和 musicId 查找收藏记录数量
    @Select("SELECT COUNT(*) FROM music_favor WHERE collector_id = #{collectorId} AND music_id = #{musicId}")
    int countByCollectorIdAndMusicId(String collectorId, String musicId);

//    // 插入新的收藏记录
//    @Insert("INSERT INTO music_favor (collector_id, music_id, favor_date, status) VALUES (#{collectorId}, #{musicId}, #{favorDate}, #{status})")
//    int insert(MusicFavor musicFavor);

    @Select("SELECT IFNULL(favor_status, 0) FROM music_favor WHERE collector_id = #{collectorId} AND music_id = #{musicId}")
    Integer queryFavorStatus(@Param("collectorId") String collectorId, @Param("musicId") String musicId);

}
